package it.polimi.swKnights.SWIMv2.servlets.administration;

import it.polimi.swKnights.SWIMv2.ejb.administration.DisputedFeebackHandlerRemote;
import it.polimi.swKnights.SWIMv2.ejb.exceptions.InvalidLoginPrivilegesException;
import it.polimi.swKnights.SWIMv2.ejb.exceptions.LoginFailException;
import it.polimi.swKnights.SWIMv2.general.Errors;
import it.polimi.swKnights.SWIMv2.servlets.SwimServlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ShowDisputedFeedback
 */
public class ShowDisputedFeedback extends SwimServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException
	{

		HttpSession session = request.getSession();
		String admin = (String) session.getAttribute("userName");
		String password = (String) session.getAttribute("password");

		String error = "";

		DisputedFeebackHandlerRemote seeFeed = this
				.lookUp(DisputedFeebackHandlerRemote.class);
		List<Map<String, String>> lstFeedback = null;

		try
		{
			lstFeedback = seeFeed.getListDisputedFeedbacks(admin, password);
			request.setAttribute("lstFeedback", lstFeedback);
			request.setAttribute("errror", error);
			request.getRequestDispatcher(
					"WEB-INF/administration/SeeDisputedFeedback.jsp").forward(
					request, response);

		}
		catch (LoginFailException e)
		{
			response.sendRedirect("./siteHome?error="+Errors.session);
		}
		catch (InvalidLoginPrivilegesException e)
		{
			response.sendRedirect("./siteHome?error="+Errors.session);
		}

	}
}
